package com.pkk.spring.cloud.web.runner.controller.ping;

import cn.hutool.core.util.StrUtil;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.pkk.spring.cloud.service.rpc.response.ResponseBody;
import com.pkk.spring.cloud.service.rpc.result.R;
import com.pkk.spring.cloud.starter.rpc.annotation.IgnoreResponseConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ping
 *
 * @author peikunkun
 * @version V1.0
 * @date 2020-12-30 14:32
 **/
@Slf4j
@RefreshScope
@RestController
@RequestMapping("ping")
public class PingController {

  @Value("${spring.test:'默认值'}")
  private String configValue;
  @Autowired
  private NacosConfigProperties nacosConfigProperties;


  @RequestMapping("/get")
  public ResponseBody<NacosConfigProperties> get() {
    return R.success(nacosConfigProperties);
  }


  @RequestMapping("/test/{message}")
  public ResponseBody<String> test(@PathVariable("message") String message) {
    return R.success(message);
  }

  @RequestMapping("/test1/{message}")
  public ResponseBody<String> test1(@PathVariable("message") String message) {
    return R.success(message);
  }


  @IgnoreResponseConverter
  @RequestMapping("/test2/{message}")
  public String test2(@PathVariable("message") String message) {
    return message;
  }


  /**
   * 消息测试
   *
   * @return java.lang.String
   * @Param message
   * @author peikunkun
   * @date 2020/12/30 0030 下午 2:36
   * @since
   */
  @RequestMapping("/{message}")
  public String ping(@PathVariable("message") String message) {
    if (StrUtil.isBlank(message)) {
      return "pang";
    }
    return message;
  }
}
